#include<iostream>
#include<functional>
using namespace std;
using placeholders::_1;
using placeholders::_2;
using placeholders::_3;

class Plus
{
    public:
        Plus(int n = 10)
        :_n(n){}
        static int plusi(int a , int b)//静态全局函数
        {
            return a + b;
        }
        double plusd(double a,double b)//类的成员函数(隐藏参数this指针)
        {
            return (a + b) * _n;
        }
    private:
        int _n;
};


int Sub(int a, int b)
{
    return (a - b) * 10;
}
int SubX(int a, int b , int c)
{
    return (a - b - c) * 10;
}

int main()
{
    auto sub1 = bind(Sub,_1,_2);//bind会返回一个仿函数对象
    cout << sub1(10,5) << std::endl;

    //调整了传参的顺序,记住_1永远是可传入的第一个参数(不常用)
    auto sub2 = bind(Sub,_2,_1);
    cout << sub2(10,5) << std::endl;

    auto sub3 = bind(SubX,_2,10,_1);
    cout << sub3(5,20) << endl;

    //成员函数的对象直接绑死,不用每次都进行传递
    //以前的写法
    function<double(Plus&&,double,double)> f1 = &Plus::plusd;
    Plus pd;
    cout << f1(move(pd),1.1,1.1) << std::endl;
    cout << f1(Plus(),1.1,1.1) << endl;

    //现在的写法
    function<double(double,double)> f2 = bind(&Plus::plusd,Plus(),_1,_2);
    cout << f2(1.1,1.1) << endl;
    return 0;
}
